package com.lazyshopkeeper.front.common;

import java.io.UnsupportedEncodingException;
import java.util.List;

import com.taobao.api.domain.Item;

public class DianneituiguangUtil {

	public static final String getDesc(String styleType,String  tuiguangName,int cosCount,int rowCount,List<Item> items){
		String desc="<table border='0' width='946' cellpadding='0' cellspacing='0' >"
	+"	<tbody>"
	+"	<tr >"
	+"		<td style='background: "+styleType+";' colspan='"+rowCount+"' height='20'><font color='black' style='font-size: 12.0px;'><strong>&nbsp;"+tuiguangName+"&nbsp;</strong></font></td>"
	+"	</tr>"
	+"	";

		for(int i =0;i<cosCount;i++){
			desc+="<tr>";
			if(items!=null){
				for(int j=0+rowCount*i ;j<items.size();j++){
					if(j%rowCount==0&&j!=0)
						break;
					desc+=getItemCode(items.get(j).getTitle(), items.get(j).getPrice(), 
							items.get(j).getPicUrl(), items.get(j).getDetailUrl());
					
				}
			}
			desc+="</tr>";
			
		}
		desc+="	<tr >"
+"			<td style='background: "+styleType+";' align='right' colspan='"+rowCount+"' height='20'><font color='black' style='font-size: 12.0px;'><strong>&nbsp;相关服务软件请查看&nbsp;</strong></td>"
+"		</tr>"
+"	</tbody>"
+"</table><br>";
//		desc=new String(desc.getBytes("ISO-8859-1"),"UTF-8");
		return desc;
	}
	
	public static final String getItemCode(String title,String price,String pirUrl,String itemUrl){
		    String Strtitle="";
		    int length=title==null?0:title.length();
			for(int i=0;i<length%15;i++){
				Strtitle+=title.substring(i*15,i*15+15)+"</br>";	
		    }
			String itemCode="	<td align='center'"
					+"			style='width: 166.0px; font-size: 12.0px; padding-top: 5.0px; padding-bottom: 5.0px; word-wrap: break-word; overflow: hidden;'"
					+"			valign='top'>"
					+"			<a href='"+itemUrl+"' target='_blank'>"
					+"			<img border='0' src='"+pirUrl+"'"
					+"				style='padding-top: 5.0px; padding-bottom: 5.0px;'/></a>"
					+"			<br>"
					+"			"
					+"			<font color='#ff0000'><b>一口价</b></font>￥&nbsp;<font"
					+"			color='#FF6600'><strong>"+price+"</strong></font>&nbsp;元<a"
					+"			href='"+itemUrl+"'"
					+"			style='font-size: 12.0px; text-decoration: none;'"
					+"			target='_blank'><br />"
					+Strtitle
					+"				</a></td>";

		return itemCode;
	}
	
	public static void main(String[] args) {
		String str="aaa";
		//System.out.println(str.getClass().);
	}
	
}
